#!/bin/bash

cd ~/programming/sport/algorithms/splay-tree
#creating directory
mkdir TMP_check_synt_test > /dev/null 2> /dev/null || rm -rf TMP_check_synt_test/*
cp -t TMP_check_synt_test/ task_splay_tree.cpp task_splay_tree_g.cpp task_set.cpp gen.cpp SplayTree_class.cpp SplayTree_class_generic.cpp
cd TMP_check_synt_test

g++ -x c++ -O2 -Wall -Wextra -pedantic task_splay_tree.cpp -o main_splay_tree -m32 || exit 1
g++ -x c++ -O2 -Wall -Wextra -pedantic task_splay_tree_g.cpp -o main_splay_tree_g -m32 || exit 1
g++ -x c++ -O2 -Wall -Wextra -pedantic task_set.cpp -o main_set -m32 || exit 1
g++ -x c++ -O2 -Wall -Wextra -pedantic gen.cpp -o gen -m32 || exit 1

for((i = 0; i < 10; ++i)); do
	echo "i = $i"
	./gen > input_$i.txt
	time ./main_splay_tree < input_$i.txt > output_splay_tree_$i.txt 2> stdlog_splay_tree_$i.txt
	time ./main_splay_tree_g < input_$i.txt > output_splay_tree_g_$i.txt 2> stdlog_splay_tree_g_$i.txt
	time ./main_set < input_$i.txt > output_set_$i.txt 2> stdlog_set_$i.txt
	if diff3 output_splay_tree_$i.txt output_set_$i.txt output_splay_tree_g_$i.txt
		then
			continue
		else
			exit 1
	fi
done

rm -rf ???*
cd ../
